
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VideoStreaming;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.media.MediaException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.m2g.SVGImage;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.VideoControl;
import net.jxta.j2me.Element;
import net.jxta.j2me.Message;
import net.jxta.j2me.PeerNetwork;
import org.netbeans.microedition.lcdui.LoginScreen;
import org.netbeans.microedition.lcdui.SimpleTableModel;
import org.netbeans.microedition.lcdui.SplashScreen;
import org.netbeans.microedition.lcdui.TableItem;
import org.netbeans.microedition.lcdui.pda.FileBrowser;

/**
 * @author naveen
 * @author ANANDSUDHAN * 
 */
public class VideoStreaming extends MIDlet implements CommandListener, Runnable {

    private boolean QUIT = false;    
    private boolean midletPaused = false;
    private String filereq; // file requested by client;to be searched
    private String peerreq; // requested peer
    private FileSharing fileobj = new FileSharing();
    private Peers peerobj = new Peers();
    // private boolean[] FilesSel = new boolean[fileobj.getFileList().size()];
    private String PeerName = null;
    private int pollcount = 0;
    private PeerNetwork peer = null;
    private boolean connectInitiated = false;
    private boolean connected = false;
    private boolean sendPending = false;
    private boolean RequestingPeer = false;

    public boolean isRequestingPeer() {
        return RequestingPeer;
    }

    public void setRequestingPeer(boolean RequestingPeer) {
        this.RequestingPeer = RequestingPeer;
    }
    public Message sendMsg;
    private Player strmplayer;
    private Player LocalPlayer;
    private byte[] incomingvid;
    private Thread pollThread = null;
    private String localVideoToPlay = null;
    private String videourl = null;
    public String getLocalVideoToPlay() {
        return localVideoToPlay;
    }

    public void setLocalVideoToPlay(String localVideoToPlay) {
        this.localVideoToPlay = localVideoToPlay;
    }

    public boolean isSendPending() {
        return sendPending;
    }

    public void setSendPending(boolean sendPending) {
        this.sendPending = sendPending;
    }
    private static final boolean DEBUG = true;
    private static final boolean QUANTIFY = true;
    private String replyBuddy = null;
    private int responseId = -1;
    private Stream strmobj = new Stream();
//   private static final String FILENAME_PREFIX = "file:///E:/share/";
 private static final String FILENAME_PREFIX = "file:///share/";
    private Item videoitem;
    private Item streamitem;

    public Item getStreamitem() {
        return streamitem;
    }

    public void setStreamitem(Item streamitem) {
        this.streamitem = streamitem;
    }
    //  byte[] state = new byte[0];
    private Configuration config = new Configuration();
    String pipeID = config.VIDEOP2P_PIPEID;

    public Configuration getConfig() {
        return config;
    }

    public void setConfig(Configuration config) {
        this.config = config;
    }

    public Item getVideoitem() {
        return videoitem;
    }

    public void setVideoitem(Item videoitem) {
        this.videoitem = videoitem;
    }
//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private List list;
    private Form Configuration;
    private TextField textField1;
    private TextField textField2;
    private TextField textField;
    private ChoiceGroup choiceGroup;
    private Spacer spacer;
    private Form Search;
    private TextField textField3;
    private TextField textField4;
    private Form form2;
    private SplashScreen splashScreen;
    private Form Connecting;
    private TableItem tableItem;
    private SplashScreen GOODBYE;
    private Form LocalFilesDIsplay;
    private ChoiceGroup choiceGroup1;
    private Form Streaming;
    private Command backCommand;
    private Command itemCommand;
    private Command backCommand1;
    private Command backCommand2;
    private Command okCommand;
    private Command itemCommand3;
    private Command itemCommand1;
    private Command itemCommand2;
    private Command backCommand3;
    private Command backCommand4;
    private Command okCommand1;
    private Command PlayCommand2;
    private Command PlayCommand;
    private Command exitCommand1;
    private Command exitCommand;
    private Command backCommand5;
    private Command okCommand2;
    private Command backCommand6;
    private Command StreamPlay;
    private SVGImage svgImage1;
    private SVGImage svgImage;
    private Image image;
    private Font font;
    private SimpleTableModel simpleTableModel;
    private Ticker ticker;
    private Font font1;
    private Image image2;
    private Image image1;
    private Image image3;
//</editor-fold>//GEN-END:|fields|0|

    public void setChoiceGroup(ChoiceGroup choiceGroup) {
        this.choiceGroup = choiceGroup;
    }
    //</editor-fold>

    /**
     * The VideoStreaming constructor.
     */
    public VideoStreaming() {
        //read the files
        LoadFiles();
    }

//<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
//</editor-fold>//GEN-END:|methods|0|
//<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initializes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
//</editor-fold>//GEN-END:|0-initialize|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getSplashScreen());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
//</editor-fold>//GEN-END:|3-startMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
//</editor-fold>//GEN-END:|4-resumeMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
//</editor-fold>//GEN-END:|5-switchDisplayable|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == Configuration) {//GEN-BEGIN:|7-commandAction|1|104-preAction
            if (command == backCommand4) {//GEN-END:|7-commandAction|1|104-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|2|104-postAction
                // write post-action user code here
            } else if (command == okCommand1) {//GEN-LINE:|7-commandAction|3|106-preAction
                // write pre-action user code here
                //PeerName = textField2.getString();
                // checking if there are any files
                //while (!fileobj.getFileList().isEmpty()) {
                for (int i = 0; i < choiceGroup.size(); i++) {
                    if (choiceGroup.isSelected(i)) // if that file is selected
                    {
                        //adding that file to file share list
                        fileobj.getFileList().addElement(choiceGroup.getString(i));
                    }
                }
                // }
                initiateConnect();
                config.storeConfig();
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|4|106-postAction


            }//GEN-BEGIN:|7-commandAction|5|118-preAction
        } else if (displayable == Connecting) {
            if (command == PlayCommand2) {//GEN-END:|7-commandAction|5|118-preAction
                // write pre-action user code here
                form2.append(getVideoitem());
//GEN-LINE:|7-commandAction|6|118-postAction
                // write post-action user code here
            } else if (command == backCommand3) {//GEN-LINE:|7-commandAction|7|90-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|8|90-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|9|126-preAction
        } else if (displayable == GOODBYE) {
            if (command == SplashScreen.DISMISS_COMMAND) {//GEN-END:|7-commandAction|9|126-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|10|126-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|11|144-preAction
        } else if (displayable == LocalFilesDIsplay) {
            if (command == backCommand6) {//GEN-END:|7-commandAction|11|144-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|12|144-postAction
                // write post-action user code here
            } else if (command == okCommand2) {//GEN-LINE:|7-commandAction|13|142-preAction
                // write pre-action user code here
                localVideoToPlay = choiceGroup1.getString(choiceGroup1.getSelectedIndex());
                String temp = FILENAME_PREFIX.concat(localVideoToPlay);
                System.out.println(temp);
                VideoPlay(temp);
                switchDisplayable(null, getForm2());//GEN-LINE:|7-commandAction|14|142-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|15|70-preAction
        } else if (displayable == Search) {
            if (command == backCommand1) {//GEN-END:|7-commandAction|15|70-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|16|70-postAction
                // write post-action user code here
            } else if (command == okCommand) {//GEN-LINE:|7-commandAction|17|74-preAction
                // write pre-action user code here
                if (textField3.size() > 0) {
                    filereq = textField3.getString();
                }
                if (textField4.size() > 0) {
                    peerreq = textField4.getString();
                }
                initiateConnect();
                //preparing file search request message
                sendMsg = peerobj.FileSearchReq(filereq, peerreq);
                //identifying this peer as Requesting Peer
                setRequestingPeer(true);
                SendMessage();
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|18|74-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|19|136-preAction
        } else if (displayable == Streaming) {
            if (command == StreamPlay) {//GEN-END:|7-commandAction|19|136-preAction
                // write pre-action user code here
                playVideo(incomingvid);
                Streaming.append(getStreamitem());
                try {
                    strmplayer.start();
                } catch (MediaException ex) {
                    ex.printStackTrace();
                }
                setRequestingPeer(false);
//GEN-LINE:|7-commandAction|20|136-postAction
                // write post-action user code here
            } else if (command == backCommand5) {//GEN-LINE:|7-commandAction|21|138-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|22|138-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|23|63-preAction
        } else if (displayable == form2) {
            if (command == backCommand) {//GEN-END:|7-commandAction|23|63-preAction
                try {
                    LocalPlayer.stop();
                } catch (MediaException ex) {
                    ex.printStackTrace();
                }
                switchDisplayable(null, getLocalFilesDIsplay());//GEN-LINE:|7-commandAction|24|63-postAction
                // write post-action user code here
            } else if (command == itemCommand) {//GEN-LINE:|7-commandAction|25|61-preAction
                //VideoPlay("http://localhost/share/natpu.mpg");
                // VideoPlay("file:///MemoryStick/SHARING/natpu.3gp");
                //VideoPlay("file:///share/natpu.3gp");
//GEN-LINE:|7-commandAction|26|61-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|27|36-preAction
        } else if (displayable == list) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|27|36-preAction
                // write pre-action user code here
                listAction();//GEN-LINE:|7-commandAction|28|36-postAction
                // write post-action user code here
            } else if (command == exitCommand1) {//GEN-LINE:|7-commandAction|29|124-preAction
                // write pre-action user code here

                switchDisplayable(null, getGOODBYE());//GEN-LINE:|7-commandAction|30|124-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|31|66-preAction
        } else if (displayable == splashScreen) {
            if (command == SplashScreen.DISMISS_COMMAND) {//GEN-END:|7-commandAction|31|66-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|32|66-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|33|7-postCommandAction
        }//GEN-END:|7-commandAction|33|7-postCommandAction
        // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|34|
//</editor-fold>//GEN-END:|7-commandAction|34|


//<editor-fold defaultstate="collapsed" desc=" Generated Getter: svgImage1 ">//GEN-BEGIN:|17-getter|0|17-preInit
    /**
     * Returns an initiliazed instance of svgImage1 component.
     * @return the initialized component instance
     */
    public SVGImage getSvgImage1() {
        if (svgImage1 == null) {//GEN-END:|17-getter|0|17-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|17-getter|1|17-@java.io.IOException
                svgImage1 = (SVGImage) SVGImage.createImage(getClass().getResourceAsStream("/Images/Menu.svg"), null);
            } catch (java.io.IOException e) {//GEN-END:|17-getter|1|17-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|17-getter|2|17-postInit
            // write post-init user code here
        }//GEN-BEGIN:|17-getter|3|
        return svgImage1;
    }
//</editor-fold>//GEN-END:|17-getter|3|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: svgImage ">//GEN-BEGIN:|27-getter|0|27-preInit
    /**
     * Returns an initiliazed instance of svgImage component.
     * @return the initialized component instance
     */
    public SVGImage getSvgImage() {
        if (svgImage == null) {//GEN-END:|27-getter|0|27-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|27-getter|1|27-@java.io.IOException
                svgImage = (SVGImage) SVGImage.createImage(getClass().getResourceAsStream("/Images/Menu.svg"), null);
            } catch (java.io.IOException e) {//GEN-END:|27-getter|1|27-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|27-getter|2|27-postInit
            // write post-init user code here
        }//GEN-BEGIN:|27-getter|3|
        return svgImage;
    }
//</editor-fold>//GEN-END:|27-getter|3|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: image ">//GEN-BEGIN:|31-getter|0|31-preInit
    /**
     * Returns an initiliazed instance of image component.
     * @return the initialized component instance
     */
    public Image getImage() {
        if (image == null) {//GEN-END:|31-getter|0|31-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|31-getter|1|31-@java.io.IOException
                image = Image.createImage("/Images/320px-Video_svg.png");
            } catch (java.io.IOException e) {//GEN-END:|31-getter|1|31-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|31-getter|2|31-postInit
            // write post-init user code here
        }//GEN-BEGIN:|31-getter|3|
        return image;
    }
//</editor-fold>//GEN-END:|31-getter|3|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: list ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of list component.
     * @return the initialized component instance
     */
    public List getList() {
        if (list == null) {//GEN-END:|34-getter|0|34-preInit
            // write pre-init user code here
            list = new List("Menu", Choice.IMPLICIT);//GEN-BEGIN:|34-getter|1|34-postInit
            list.append("Playlocal", null);
            list.append("Stream", null);
            list.append("Configuration", null);
            list.append("Search", null);
            list.addCommand(getExitCommand1());
            list.setCommandListener(this);
            list.setSelectedFlags(new boolean[]{false, false, false, false});//GEN-END:|34-getter|1|34-postInit
            // write post-init user code here
        }//GEN-BEGIN:|34-getter|2|
        return list;
    }
//</editor-fold>//GEN-END:|34-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: listAction ">//GEN-BEGIN:|34-action|0|34-preAction
    /**
     * Performs an action assigned to the selected list element in the list component.
     */
    public void listAction() {//GEN-END:|34-action|0|34-preAction
        // enter pre-action user code here
        String __selectedString = getList().getString(getList().getSelectedIndex());//GEN-BEGIN:|34-action|1|40-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Playlocal")) {//GEN-END:|34-action|1|40-preAction
                // write pre-action user code here
                switchDisplayable(null, getLocalFilesDIsplay());//GEN-LINE:|34-action|2|40-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Stream")) {//GEN-LINE:|34-action|3|41-preAction
                // write pre-action user code here

                switchDisplayable(null, getStreaming());//GEN-LINE:|34-action|4|41-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Configuration")) {//GEN-LINE:|34-action|5|42-preAction
                // write pre-action user code here
                switchDisplayable(null, getConfiguration());//GEN-LINE:|34-action|6|42-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Search")) {//GEN-LINE:|34-action|7|75-preAction
                // write pre-action user code here
                switchDisplayable(null, getSearch());//GEN-LINE:|34-action|8|75-postAction
                // write post-action user code here
            }//GEN-BEGIN:|34-action|9|34-postAction
        }//GEN-END:|34-action|9|34-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|34-action|10|
//</editor-fold>//GEN-END:|34-action|10|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: font ">//GEN-BEGIN:|33-getter|0|33-preInit
    /**
     * Returns an initiliazed instance of font component.
     * @return the initialized component instance
     */
    public Font getFont() {
        if (font == null) {//GEN-END:|33-getter|0|33-preInit
            // write pre-init user code here
            font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC, Font.SIZE_LARGE);//GEN-LINE:|33-getter|1|33-postInit
            // write post-init user code here
        }//GEN-BEGIN:|33-getter|2|
        return font;
    }
//</editor-fold>//GEN-END:|33-getter|2|
    //</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: Configuration ">//GEN-BEGIN:|43-getter|0|43-preInit
    /**
     * Returns an initiliazed instance of Configuration component.
     * @return the initialized component instance
     */
    public Form getConfiguration() {
        if (Configuration == null) {//GEN-END:|43-getter|0|43-preInit
            // write pre-init user code here
            getChoiceGroup();
            // choiceGroup = new ChoiceGroup("Files To Share", Choice.MULTIPLE);
            for (int i = 0; i < fileobj.getLocalFiles().size(); i++) {
                choiceGroup.append((String) fileobj.getLocalFiles().elementAt(i), null);
            }
            Configuration = new Form("Configuration", new Item[]{getTextField(), getTextField1(), getTextField2(), getSpacer(), getChoiceGroup()});//GEN-BEGIN:|43-getter|1|43-postInit
            Configuration.addCommand(getBackCommand4());
            Configuration.addCommand(getOkCommand1());
            Configuration.setCommandListener(this);//GEN-END:|43-getter|1|43-postInit
            // write post-init user code here
        }//GEN-BEGIN:|43-getter|2|
        return Configuration;
    }
//</editor-fold>//GEN-END:|43-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField ">//GEN-BEGIN:|45-getter|0|45-preInit
    /**
     * Returns an initiliazed instance of textField component.
     * @return the initialized component instance
     */
    public TextField getTextField() {
        if (textField == null) {//GEN-END:|45-getter|0|45-preInit
            // write pre-init user code here
            textField = new TextField("Relay host", "xxx.xxx.xxx.xxx", 32, TextField.ANY);//GEN-LINE:|45-getter|1|45-postInit
            // write post-init user code here
        }//GEN-BEGIN:|45-getter|2|
        return textField;
    }
//</editor-fold>//GEN-END:|45-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField1 ">//GEN-BEGIN:|46-getter|0|46-preInit
    /**
     * Returns an initiliazed instance of textField1 component.
     * @return the initialized component instance
     */
    public TextField getTextField1() {
        if (textField1 == null) {//GEN-END:|46-getter|0|46-preInit
            // write pre-init user code here
            textField1 = new TextField("Relay port", "9700", 32, TextField.ANY);//GEN-LINE:|46-getter|1|46-postInit
            // write post-init user code here
        }//GEN-BEGIN:|46-getter|2|
        return textField1;
    }
//</editor-fold>//GEN-END:|46-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField2 ">//GEN-BEGIN:|47-getter|0|47-preInit
    /**
     * Returns an initiliazed instance of textField2 component.
     * @return the initialized component instance
     */
    public TextField getTextField2() {
        if (textField2 == null) {//GEN-END:|47-getter|0|47-preInit
            // write pre-init user code here
            textField2 = new TextField("Name", "name", 32, TextField.ANY);//GEN-LINE:|47-getter|1|47-postInit
            // write post-init user code here
        }//GEN-BEGIN:|47-getter|2|
        return textField2;
    }
//</editor-fold>//GEN-END:|47-getter|2|
    //</editor-fold>
    //</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: Search ">//GEN-BEGIN:|50-getter|0|50-preInit
    /**
     * Returns an initiliazed instance of Search component.
     * @return the initialized component instance
     */
    public Form getSearch() {
        if (Search == null) {//GEN-END:|50-getter|0|50-preInit
            // write pre-init user code here
            Search = new Form("Search", new Item[]{getTextField3(), getTextField4()});//GEN-BEGIN:|50-getter|1|50-postInit
            Search.addCommand(getBackCommand1());
            Search.addCommand(getOkCommand());
            Search.setCommandListener(this);//GEN-END:|50-getter|1|50-postInit
            // write post-init user code here
        }//GEN-BEGIN:|50-getter|2|
        return Search;
    }
//</editor-fold>//GEN-END:|50-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField3 ">//GEN-BEGIN:|52-getter|0|52-preInit
    /**
     * Returns an initiliazed instance of textField3 component.
     * @return the initialized component instance
     */
    public TextField getTextField3() {
        if (textField3 == null) {//GEN-END:|52-getter|0|52-preInit
            // write pre-init user code here
            textField3 = new TextField("Search", "Search", 32, TextField.ANY);//GEN-LINE:|52-getter|1|52-postInit
            // write post-init user code here
        }//GEN-BEGIN:|52-getter|2|
        return textField3;
    }
//</editor-fold>//GEN-END:|52-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: form2 ">//GEN-BEGIN:|57-getter|0|57-preInit
    /**
     * Returns an initiliazed instance of form2 component.
     * @return the initialized component instance
     */
    public Form getForm2() {
        if (form2 == null) {//GEN-END:|57-getter|0|57-preInit
            // write pre-init user code here
            form2 = new Form("Play", new Item[]{});//GEN-BEGIN:|57-getter|1|57-postInit
            form2.addCommand(getItemCommand());
            form2.addCommand(getBackCommand());
            form2.setCommandListener(this);//GEN-END:|57-getter|1|57-postInit
            // write post-init user code here
        }//GEN-BEGIN:|57-getter|2|
        return form2;
    }
//</editor-fold>//GEN-END:|57-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand ">//GEN-BEGIN:|60-getter|0|60-preInit
    /**
     * Returns an initiliazed instance of itemCommand component.
     * @return the initialized component instance
     */
    public Command getItemCommand() {
        if (itemCommand == null) {//GEN-END:|60-getter|0|60-preInit

            itemCommand = new Command("Play", "Refresh", Command.ITEM, 0);//GEN-LINE:|60-getter|1|60-postInit

        }//GEN-BEGIN:|60-getter|2|
        return itemCommand;
    }
//</editor-fold>//GEN-END:|60-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|62-getter|0|62-preInit
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|62-getter|0|62-preInit
            // write pre-init user code here
            backCommand = new Command("Back", Command.BACK, 0);//GEN-LINE:|62-getter|1|62-postInit
            // write post-init user code here
        }//GEN-BEGIN:|62-getter|2|
        return backCommand;
    }
//</editor-fold>//GEN-END:|62-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: splashScreen ">//GEN-BEGIN:|65-getter|0|65-preInit
    /**
     * Returns an initiliazed instance of splashScreen component.
     * @return the initialized component instance
     */
    public SplashScreen getSplashScreen() {
        if (splashScreen == null) {//GEN-END:|65-getter|0|65-preInit
            // write pre-init user code here
            splashScreen = new SplashScreen(getDisplay());//GEN-BEGIN:|65-getter|1|65-postInit
            splashScreen.setTitle("WELCOME!!!");
            splashScreen.setCommandListener(this);
            splashScreen.setImage(getImage1());//GEN-END:|65-getter|1|65-postInit
            // write post-init user code here
        }//GEN-BEGIN:|65-getter|2|
        return splashScreen;
    }
//</editor-fold>//GEN-END:|65-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|69-getter|0|69-preInit
    /**
     * Returns an initiliazed instance of backCommand1 component.
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {//GEN-END:|69-getter|0|69-preInit
            // write pre-init user code here
            backCommand1 = new Command("Back", Command.BACK, 0);//GEN-LINE:|69-getter|1|69-postInit
            // write post-init user code here
        }//GEN-BEGIN:|69-getter|2|
        return backCommand1;
    }
//</editor-fold>//GEN-END:|69-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: textField4 ">//GEN-BEGIN:|72-getter|0|72-preInit
    /**
     * Returns an initiliazed instance of textField4 component.
     * @return the initialized component instance
     */
    public TextField getTextField4() {
        if (textField4 == null) {//GEN-END:|72-getter|0|72-preInit
            // write pre-init user code here
            textField4 = new TextField("Search a Particular Peer", "xxx.xxx.xxx.xxx", 32, TextField.ANY);//GEN-LINE:|72-getter|1|72-postInit
            // write post-init user code here
        }//GEN-BEGIN:|72-getter|2|
        return textField4;
    }
//</editor-fold>//GEN-END:|72-getter|2|
    //</editor-fold>
    //</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">//GEN-BEGIN:|73-getter|0|73-preInit
    /**
     * Returns an initiliazed instance of okCommand component.
     * @return the initialized component instance
     */
    public Command getOkCommand() {
        if (okCommand == null) {//GEN-END:|73-getter|0|73-preInit
            // write pre-init user code here
            okCommand = new Command("Ok", Command.OK, 0);//GEN-LINE:|73-getter|1|73-postInit
            // write post-init user code here

        }//GEN-BEGIN:|73-getter|2|
        return okCommand;
    }
//</editor-fold>//GEN-END:|73-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand2 ">//GEN-BEGIN:|77-getter|0|77-preInit
    /**
     * Returns an initiliazed instance of backCommand2 component.
     * @return the initialized component instance
     */
    public Command getBackCommand2() {
        if (backCommand2 == null) {//GEN-END:|77-getter|0|77-preInit
            // write pre-init user code here
            backCommand2 = new Command("Back", Command.BACK, 0);//GEN-LINE:|77-getter|1|77-postInit
            // write post-init user code here
        }//GEN-BEGIN:|77-getter|2|
        return backCommand2;
    }
//</editor-fold>//GEN-END:|77-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: Connecting ">//GEN-BEGIN:|87-getter|0|87-preInit
    /**
     * Returns an initiliazed instance of Connecting component.
     * @return the initialized component instance
     */
    public Form getConnecting() {
        if (Connecting == null) {//GEN-END:|87-getter|0|87-preInit
            // write pre-init user code here
            Connecting = new Form("form1", new Item[]{getTableItem()});//GEN-BEGIN:|87-getter|1|87-postInit
            Connecting.addCommand(getBackCommand3());
            Connecting.addCommand(getPlayCommand2());
            Connecting.setCommandListener(this);//GEN-END:|87-getter|1|87-postInit
            // write post-init user code here
        }//GEN-BEGIN:|87-getter|2|
        return Connecting;
    }
//</editor-fold>//GEN-END:|87-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand1 ">//GEN-BEGIN:|80-getter|0|80-preInit
    /**
     * Returns an initiliazed instance of itemCommand1 component.
     * @return the initialized component instance
     */
    public Command getItemCommand1() {
        if (itemCommand1 == null) {//GEN-END:|80-getter|0|80-preInit
            // write pre-init user code here
            itemCommand1 = new Command("Connect", Command.ITEM, 0);//GEN-LINE:|80-getter|1|80-postInit
            // write post-init user code here
        }//GEN-BEGIN:|80-getter|2|
        return itemCommand1;
    }
//</editor-fold>//GEN-END:|80-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand2 ">//GEN-BEGIN:|82-getter|0|82-preInit
    /**
     * Returns an initiliazed instance of itemCommand2 component.
     * @return the initialized component instance
     */
    public Command getItemCommand2() {
        if (itemCommand2 == null) {//GEN-END:|82-getter|0|82-preInit
            // write pre-init user code here
            itemCommand2 = new Command("Item", "<null>", Command.ITEM, 0);//GEN-LINE:|82-getter|1|82-postInit
            // write post-init user code here
        }//GEN-BEGIN:|82-getter|2|
        return itemCommand2;
    }
//</editor-fold>//GEN-END:|82-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand3 ">//GEN-BEGIN:|84-getter|0|84-preInit
    /**
     * Returns an initiliazed instance of itemCommand3 component.
     * @return the initialized component instance
     */
    public Command getItemCommand3() {
        if (itemCommand3 == null) {//GEN-END:|84-getter|0|84-preInit
            // write pre-init user code here
            itemCommand3 = new Command("Item", Command.ITEM, 0);//GEN-LINE:|84-getter|1|84-postInit
            // write post-init user code here
        }//GEN-BEGIN:|84-getter|2|
        return itemCommand3;
    }
//</editor-fold>//GEN-END:|84-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand3 ">//GEN-BEGIN:|89-getter|0|89-preInit
    /**
     * Returns an initiliazed instance of backCommand3 component.
     * @return the initialized component instance
     */
    public Command getBackCommand3() {
        if (backCommand3 == null) {//GEN-END:|89-getter|0|89-preInit
            // write pre-init user code here
            backCommand3 = new Command("Back", Command.BACK, 0);//GEN-LINE:|89-getter|1|89-postInit
            // write post-init user code here
        }//GEN-BEGIN:|89-getter|2|
        return backCommand3;
    }
//</editor-fold>//GEN-END:|89-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: simpleTableModel ">//GEN-BEGIN:|91-getter|0|91-preInit
    /**
     * Returns an initiliazed instance of simpleTableModel component.
     * @return the initialized component instance
     */
    public SimpleTableModel getSimpleTableModel() {
        if (simpleTableModel == null) {//GEN-END:|91-getter|0|91-preInit
            // write pre-init user code here
            simpleTableModel = new SimpleTableModel(new java.lang.String[][]{//GEN-BEGIN:|91-getter|1|91-postInit
                        new java.lang.String[]{""}}, null);//GEN-END:|91-getter|1|91-postInit
            // write post-init user code here
        }//GEN-BEGIN:|91-getter|2|
        return simpleTableModel;
    }
//</editor-fold>//GEN-END:|91-getter|2|



//<editor-fold defaultstate="collapsed" desc=" Generated Getter: ticker ">//GEN-BEGIN:|96-getter|0|96-preInit
    /**
     * Returns an initiliazed instance of ticker component.
     * @return the initialized component instance
     */
    public Ticker getTicker() {
        if (ticker == null) {//GEN-END:|96-getter|0|96-preInit
            // write pre-init user code here
            ticker = new Ticker("");//GEN-LINE:|96-getter|1|96-postInit
            // write post-init user code here
        }//GEN-BEGIN:|96-getter|2|
        return ticker;
    }
//</editor-fold>//GEN-END:|96-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: spacer ">//GEN-BEGIN:|99-getter|0|99-preInit
    /**
     * Returns an initiliazed instance of spacer component.
     * @return the initialized component instance
     */
    public Spacer getSpacer() {
        if (spacer == null) {//GEN-END:|99-getter|0|99-preInit
            // write pre-init user code here
            spacer = new Spacer(16, 1);//GEN-LINE:|99-getter|1|99-postInit
            // write post-init user code here
        }//GEN-BEGIN:|99-getter|2|
        return spacer;
    }
//</editor-fold>//GEN-END:|99-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: choiceGroup ">//GEN-BEGIN:|100-getter|0|100-preInit
    /**
     * Returns an initiliazed instance of choiceGroup component.
     * @return the initialized component instance
     */
    public ChoiceGroup getChoiceGroup() {
        if (choiceGroup == null) {//GEN-END:|100-getter|0|100-preInit
            // write pre-init user code here
            choiceGroup = new ChoiceGroup("Files To Share", Choice.MULTIPLE);//GEN-BEGIN:|100-getter|1|100-postInit
            choiceGroup.setSelectedFlags(new boolean[]{});//GEN-END:|100-getter|1|100-postInit
            // write post-init user code here
        }//GEN-BEGIN:|100-getter|2|
        return choiceGroup;
    }
//</editor-fold>//GEN-END:|100-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand4 ">//GEN-BEGIN:|103-getter|0|103-preInit
    /**
     * Returns an initiliazed instance of backCommand4 component.
     * @return the initialized component instance
     */
    public Command getBackCommand4() {
        if (backCommand4 == null) {//GEN-END:|103-getter|0|103-preInit
            // write pre-init user code here
            backCommand4 = new Command("Back", Command.BACK, 0);//GEN-LINE:|103-getter|1|103-postInit
            // write post-init user code here
        }//GEN-BEGIN:|103-getter|2|
        return backCommand4;
    }
//</editor-fold>//GEN-END:|103-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand1 ">//GEN-BEGIN:|105-getter|0|105-preInit
    /**
     * Returns an initiliazed instance of okCommand1 component.
     * @return the initialized component instance
     */
    public Command getOkCommand1() {
        if (okCommand1 == null) {//GEN-END:|105-getter|0|105-preInit
            // write pre-init user code here
            okCommand1 = new Command("Ok", Command.OK, 0);//GEN-LINE:|105-getter|1|105-postInit
            // write post-init user code here
        }//GEN-BEGIN:|105-getter|2|
        return okCommand1;
    }
//</editor-fold>//GEN-END:|105-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: tableItem ">//GEN-BEGIN:|114-getter|0|114-preInit
    /**
     * Returns an initiliazed instance of tableItem component.
     * @return the initialized component instance
     */
    public TableItem getTableItem() {
        if (tableItem == null) {//GEN-END:|114-getter|0|114-preInit
            // write pre-init user code here
            tableItem = new TableItem(getDisplay(), "Connected Peer Sources");//GEN-BEGIN:|114-getter|1|114-postInit
            tableItem.setModel(getSimpleTableModel());//GEN-END:|114-getter|1|114-postInit
            // write post-init user code here
        }//GEN-BEGIN:|114-getter|2|
        return tableItem;
    }
//</editor-fold>//GEN-END:|114-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: PlayCommand ">//GEN-BEGIN:|115-getter|0|115-preInit
    /**
     * Returns an initiliazed instance of PlayCommand component.
     * @return the initialized component instance
     */
    public Command getPlayCommand() {
        if (PlayCommand == null) {//GEN-END:|115-getter|0|115-preInit
            // write pre-init user code here
            PlayCommand = new Command("Screen", Command.SCREEN, 0);//GEN-LINE:|115-getter|1|115-postInit
            // write post-init user code here
        }//GEN-BEGIN:|115-getter|2|
        return PlayCommand;
    }
//</editor-fold>//GEN-END:|115-getter|2|
    //</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: PlayCommand2 ">//GEN-BEGIN:|117-getter|0|117-preInit
    /**
     * Returns an initiliazed instance of PlayCommand2 component.
     * @return the initialized component instance
     */
    public Command getPlayCommand2() {
        if (PlayCommand2 == null) {//GEN-END:|117-getter|0|117-preInit
            // write pre-init user code here
            PlayCommand2 = new Command("Ok", Command.OK, 0);//GEN-LINE:|117-getter|1|117-postInit
            // write post-init user code here
        }//GEN-BEGIN:|117-getter|2|
        return PlayCommand2;
    }
//</editor-fold>//GEN-END:|117-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|121-getter|0|121-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|121-getter|0|121-preInit
            // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|121-getter|1|121-postInit
            // write post-init user code here
        }//GEN-BEGIN:|121-getter|2|
        return exitCommand;
    }
//</editor-fold>//GEN-END:|121-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand1 ">//GEN-BEGIN:|123-getter|0|123-preInit
    /**
     * Returns an initiliazed instance of exitCommand1 component.
     * @return the initialized component instance
     */
    public Command getExitCommand1() {
        if (exitCommand1 == null) {//GEN-END:|123-getter|0|123-preInit
            // write pre-init user code here
            exitCommand1 = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|123-getter|1|123-postInit
            // write post-init user code here
        }//GEN-BEGIN:|123-getter|2|
        return exitCommand1;
    }
//</editor-fold>//GEN-END:|123-getter|2|
    //</editor-fold>

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: GOODBYE ">//GEN-BEGIN:|125-getter|0|125-preInit
    /**
     * Returns an initiliazed instance of GOODBYE component.
     * @return the initialized component instance
     */
    public SplashScreen getGOODBYE() {
        if (GOODBYE == null) {//GEN-END:|125-getter|0|125-preInit
            // write pre-init user code here
            GOODBYE = new SplashScreen(getDisplay());//GEN-BEGIN:|125-getter|1|125-postInit
            GOODBYE.setTitle("GOOD BYE!!!");
            GOODBYE.setCommandListener(this);
            GOODBYE.setImage(getImage3());
            GOODBYE.setText("");
            GOODBYE.setTextFont(getFont());//GEN-END:|125-getter|1|125-postInit
            // write post-init user code here
        }//GEN-BEGIN:|125-getter|2|
        return GOODBYE;
    }
//</editor-fold>//GEN-END:|125-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: font1 ">//GEN-BEGIN:|129-getter|0|129-preInit
    /**
     * Returns an initiliazed instance of font1 component.
     * @return the initialized component instance
     */
    public Font getFont1() {
        if (font1 == null) {//GEN-END:|129-getter|0|129-preInit
            // write pre-init user code here
            font1 = Font.getDefaultFont();//GEN-LINE:|129-getter|1|129-postInit
            // write post-init user code here
        }//GEN-BEGIN:|129-getter|2|
        return font1;
    }
//</editor-fold>//GEN-END:|129-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: image1 ">//GEN-BEGIN:|130-getter|0|130-preInit
    /**
     * Returns an initiliazed instance of image1 component.
     * @return the initialized component instance
     */
    public Image getImage1() {
        if (image1 == null) {//GEN-END:|130-getter|0|130-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|130-getter|1|130-@java.io.IOException
                image1 = Image.createImage("/Images/Zoo_Zoo_Salute.jpg");
            } catch (java.io.IOException e) {//GEN-END:|130-getter|1|130-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|130-getter|2|130-postInit
            // write post-init user code here
        }//GEN-BEGIN:|130-getter|3|
        return image1;
    }
//</editor-fold>//GEN-END:|130-getter|3|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: image2 ">//GEN-BEGIN:|131-getter|0|131-preInit
    /**
     * Returns an initiliazed instance of image2 component.
     * @return the initialized component instance
     */
    public Image getImage2() {
        if (image2 == null) {//GEN-END:|131-getter|0|131-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|131-getter|1|131-@java.io.IOException
                image2 = Image.createImage("/Images/Be_Back.jpg");
            } catch (java.io.IOException e) {//GEN-END:|131-getter|1|131-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|131-getter|2|131-postInit
            // write post-init user code here
        }//GEN-BEGIN:|131-getter|3|
        return image2;
    }
//</editor-fold>//GEN-END:|131-getter|3|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: image3 ">//GEN-BEGIN:|132-getter|0|132-preInit
    /**
     * Returns an initiliazed instance of image3 component.
     * @return the initialized component instance
     */
    public Image getImage3() {
        if (image3 == null) {//GEN-END:|132-getter|0|132-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|132-getter|1|132-@java.io.IOException
                image3 = Image.createImage("/Images/Zoo_Zoo_Sky.jpg");
            } catch (java.io.IOException e) {//GEN-END:|132-getter|1|132-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|132-getter|2|132-postInit
            // write post-init user code here
        }//GEN-BEGIN:|132-getter|3|
        return image3;
    }
//</editor-fold>//GEN-END:|132-getter|3|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: Streaming ">//GEN-BEGIN:|134-getter|0|134-preInit
    /**
     * Returns an initiliazed instance of Streaming component.
     * @return the initialized component instance
     */
    public Form getStreaming() {
        if (Streaming == null) {//GEN-END:|134-getter|0|134-preInit
            // write pre-init user code here
            Streaming = new Form("STREAMING");//GEN-BEGIN:|134-getter|1|134-postInit
            Streaming.addCommand(getStreamPlay());
            Streaming.addCommand(getBackCommand5());
            Streaming.setCommandListener(this);//GEN-END:|134-getter|1|134-postInit
            // write post-init user code here
        }//GEN-BEGIN:|134-getter|2|
        return Streaming;
    }
//</editor-fold>//GEN-END:|134-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: StreamPlay ">//GEN-BEGIN:|135-getter|0|135-preInit
    /**
     * Returns an initiliazed instance of StreamPlay component.
     * @return the initialized component instance
     */
    public Command getStreamPlay() {
        if (StreamPlay == null) {//GEN-END:|135-getter|0|135-preInit
            // write pre-init user code here
            StreamPlay = new Command("Item", Command.ITEM, 0);//GEN-LINE:|135-getter|1|135-postInit
            // write post-init user code here
        }//GEN-BEGIN:|135-getter|2|
        return StreamPlay;
    }
//</editor-fold>//GEN-END:|135-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand5 ">//GEN-BEGIN:|137-getter|0|137-preInit
    /**
     * Returns an initiliazed instance of backCommand5 component.
     * @return the initialized component instance
     */
    public Command getBackCommand5() {
        if (backCommand5 == null) {//GEN-END:|137-getter|0|137-preInit
            // write pre-init user code here
            backCommand5 = new Command("Back", Command.BACK, 0);//GEN-LINE:|137-getter|1|137-postInit
            // write post-init user code here
        }//GEN-BEGIN:|137-getter|2|
        return backCommand5;
    }
//</editor-fold>//GEN-END:|137-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: LocalFilesDIsplay ">//GEN-BEGIN:|140-getter|0|140-preInit
    /**
     * Returns an initiliazed instance of LocalFilesDIsplay component.
     * @return the initialized component instance
     */
    public Form getLocalFilesDIsplay() {
        if (LocalFilesDIsplay == null) {//GEN-END:|140-getter|0|140-preInit
            // write pre-init user code here
            getChoiceGroup1();
            for (int i = 0; i < fileobj.getLocalFiles().size(); i++) {
                choiceGroup1.append((String) fileobj.getLocalFiles().elementAt(i), null);
            }
            LocalFilesDIsplay = new Form("Local Files", new Item[]{getChoiceGroup1()});//GEN-BEGIN:|140-getter|1|140-postInit
            LocalFilesDIsplay.addCommand(getOkCommand2());
            LocalFilesDIsplay.addCommand(getBackCommand6());
            LocalFilesDIsplay.setCommandListener(this);//GEN-END:|140-getter|1|140-postInit
            // write post-init user code here

        }//GEN-BEGIN:|140-getter|2|
        return LocalFilesDIsplay;
    }
//</editor-fold>//GEN-END:|140-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: choiceGroup1 ">//GEN-BEGIN:|147-getter|0|147-preInit
    /**
     * Returns an initiliazed instance of choiceGroup1 component.
     * @return the initialized component instance
     */
    public ChoiceGroup getChoiceGroup1() {
        if (choiceGroup1 == null) {//GEN-END:|147-getter|0|147-preInit
            // write pre-init user code here
            choiceGroup1 = new ChoiceGroup("Files in Share", Choice.EXCLUSIVE);//GEN-LINE:|147-getter|1|147-postInit
            // write post-init user code here
        }//GEN-BEGIN:|147-getter|2|
        return choiceGroup1;
    }
//</editor-fold>//GEN-END:|147-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand2 ">//GEN-BEGIN:|141-getter|0|141-preInit
    /**
     * Returns an initiliazed instance of okCommand2 component.
     * @return the initialized component instance
     */
    public Command getOkCommand2() {
        if (okCommand2 == null) {//GEN-END:|141-getter|0|141-preInit
            // write pre-init user code here
            okCommand2 = new Command("Ok", Command.OK, 0);//GEN-LINE:|141-getter|1|141-postInit
            // write post-init user code here
        }//GEN-BEGIN:|141-getter|2|
        return okCommand2;
    }
//</editor-fold>//GEN-END:|141-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand6 ">//GEN-BEGIN:|143-getter|0|143-preInit
    /**
     * Returns an initiliazed instance of backCommand6 component.
     * @return the initialized component instance
     */
    public Command getBackCommand6() {
        if (backCommand6 == null) {//GEN-END:|143-getter|0|143-preInit
            // write pre-init user code here
            backCommand6 = new Command("Back", Command.BACK, 0);//GEN-LINE:|143-getter|1|143-postInit
            // write post-init user code here
        }//GEN-BEGIN:|143-getter|2|
        return backCommand6;
    }
//</editor-fold>//GEN-END:|143-getter|2|



    public void VideoPlay(String videoURL) {
        try {
            //String url = "http://localhost/natpu.mpg";
            byte[] buf = strmobj.videotobytearray(videoURL);
            ByteArrayInputStream input = new ByteArrayInputStream(buf);
            LocalPlayer = Manager.createPlayer(input, "video/3gpp");
            LocalPlayer.realize();
            //Get the video controller
            VideoControl video = (VideoControl) LocalPlayer.getControl("VideoControl");

            //Get a GUI to display the video
            setVideoitem((Item) video.initDisplayMode(
                    VideoControl.USE_GUI_PRIMITIVE, null));

            //Append the GUI to a form
            form2.append(getVideoitem());

            //Start the video
            LocalPlayer.start();
        } catch (Exception e) {
        }
    }

    public synchronized boolean poll() {

        if (peer == null || !connected) {
            // not yet connected
            return false;
        }
        Message pollMsg = null;
        String ReqPeer = null;
        String buddyname = null;// getting the name from reply element
        String FileReq = null;
        boolean buddyfound = false;
        //  pollcount++;

        try {
            long startTime, endTime;
            if (QUANTIFY) {
                startTime = System.currentTimeMillis();
            }
            // timeout must not be zero: zero means block forever
            if (peer != null) {
                pollMsg = peer.poll(config.getPollInterval() * 100);
            }
            if (QUANTIFY) {
                endTime = System.currentTimeMillis();
                System.out.println("poll took "
                        + Long.toString(endTime - startTime));
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            return false;
        }
        if (pollMsg == null) {
            return false;
        }

        System.out.println("MEssage SIZE :" + pollMsg.getSize());
        Element elm = null;
        String id = null;
        String peername = null;// getting the name from peer messgage

        for (int i = 0; i < pollMsg.getElementCount(); i++)
        {
            elm = pollMsg.getElement(i);
            if (Message.PROXY_NAME_SPACE.equals(elm.getNameSpace()))
            {
                String elementName = elm.getName();
                System.out.println("PROXY NAME SPACE*******" + elementName + "*********");
                if (Message.NAME_TAG.equals(elementName))
                {
                    peername = new String(elm.getData());
                    System.out.println("NAME TAG*********" + peername + "*******");
                } else if (Message.ID_TAG.equals(elementName)) {
                    id = new String(elm.getData());
                    System.out.println("ID TAG*********" + id + "*******");
                }
            }
        }

        //validating buddy if not true adding buddy to hashtable
        /*for (int i = 0; i < peerobj.getPeerList().size(); i++) {
        if (peerobj.getPeerList().containsKey(peername)) {
        peerobj.getPeerList().put(peername, id);
        }
        }*/

        for (int i = 0; i < pollMsg.getElementCount(); i++) {
            elm = pollMsg.getElement(i);
            if ("requestId".equals(elm.getName())) {
                responseId = Integer.parseInt(new String(elm.getData()));
                System.out.println("ResponseId: " + responseId);
            } else if ("ReqPeerName".equals(elm.getName())) {
                ReqPeer = new String(elm.getData());
                System.out.println("VIDEOSTREAMING---> reqpeername");
            } else if ("ReqFileName".equals(elm.getName())) {
                FileReq = new String(elm.getData());
                System.out.println("VIDEOSTREAMING---> reqfilename");
            } else if ("PeerReply".equals(elm.getName())) {
                //send the confirmation
                buddyname = new String(elm.getData());
                peerobj.getVideoPeers().addElement(elm.getData());
            } else if ("ReqConfirm".equals(elm.getName())) {
                //send the video to the req peer
                if(fileobj.getFilename() != null)
                buddyfound = true;
                //peerobj.getVideoPeers().addElement(elm.getData());
               // peerobj.setCurrentbuddy(elm.getData().toString());
            } else if ("JxmeVideo".equals(elm.getName())&& isRequestingPeer()) {
                // play the video
                incomingvid = elm.getData();
                //playVideo(elm.getData());
                // form2.append(getVideoitem());
                switchDisplayable(null, getStreaming());

            }
        }
        // if a search request has come in
        if (ReqPeer != null && FileReq != null && !isRequestingPeer()) {
            System.out.println("VIDEOSTREAMING--------> searchrequest" + FileReq);
            if (peerobj.Search(FileReq, fileobj)) {

                fileobj.setFilename(FileReq);
                System.out.println("VIDEOSTREAMING-----1---> searchFILEFOUND");
                Element[] elmobj = new Element[2];
                System.out.println("VIDEOSTREAMING----2----> searchFILEFOUND");
                elmobj[0] = new Element("PeerReply", peerobj.getName().getBytes(), null, null);
                elmobj[1] = new Element("FileReply", "TRUE".getBytes(), null, null);
                sendMsg = new Message(elmobj);
                System.out.println("VIDEOSTREAMING-----3---> searchFILEFOUND");
                SendMessage();
            }else System.out.println("no FILE MATCH FOUND!!!");
        } //if a reply for video comes through as positive
        else if (buddyname != null) {// && pollcount == 2) {
            String sendname = null;
            Element[] elmobj = new Element[1];
            elmobj[0] = new Element("ReqConfirm", peerobj.getName().getBytes(), null, null);
            sendMsg = new Message(elmobj);
            SendMessage();
        } //if a confirmation to send is received
        else if (buddyfound) {
            //send the video
            //videourl = FILENAME_PREFIX+FileReq;
            System.out.println("FIlenmae preIFX: "+FILENAME_PREFIX);
            System.out.println(" fileojb.getfilename : "+fileobj.getFilename());
            videourl = FILENAME_PREFIX+fileobj.getFilename();
            System.out.println("videourl------> : "+videourl);
            sendMsg = strmobj.send(1, videourl);
            //sendMsg = strmobj.send(peerobj.getVideoPeers().size(), videourl);
            //SendMessage(msg, peerobj.getCurrentbuddy());
            SendMessage();
        }
        return true;
    }

    // Loading the file names in the share folder
    public void LoadFiles() {
        String filename;
     String folderpath = "file:///share/";
//       String folderpath = "file:///E:/share/";
        try {
            FileConnection folder = (FileConnection) Connector.open(folderpath);
            Enumeration files = folder.list();

            while (files.hasMoreElements()) {
                System.out.println("inside while loop");
                filename = (String) files.nextElement();
                //choiceGroup.append(filename, null); // loading the choice group with the available files
                fileobj.getLocalFiles().addElement(filename); // adding the files to list
            }
            folder.close();
        } catch (Exception e) {
            System.out.println("Cannot Load Files!!!");
            e.printStackTrace();
        }
    }

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        QUIT = false;
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
            try {
                config.readConfig();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        pollThread = new Thread(this);
        pollThread.start();
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
        QUIT = true;
        pollThread = null;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
        config.storeConfig();
        QUIT = true;
        pollThread = null;
    }

    public synchronized void run() {

        while (!QUIT) {
            try {
                if (!connected && connectInitiated) {
                    connect(getTextField().getString(), getTextField1().getString(), getTextField2().getString(), "JxtaPropagate");
                    if (sendPending) {
                        SendMessage();
                        sendPending = false;
                    }
                }
                while (poll()) {
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            try { // poll interval is specified in seconds
                Thread.currentThread().sleep(config.getPollInterval() * 1000);
            } catch (InterruptedException ignore) {
            }
        }
    }

    public synchronized boolean connect(String relayhost, String relayport, String Id, String pipeType) throws Exception {
        connectInitiated = false;
        int port = 0;
        try {
            port = Integer.parseInt(relayport);
        } catch (NumberFormatException ex) {
            return false;
        }
        String url = "http://" + relayhost + ":" + Integer.toString(port);
        long startTime, endTime;
        if (QUANTIFY) {
            startTime = System.currentTimeMillis();
        }
        //connecting to a relay
        config.state = peer.connect(url, config.state);
        if (QUANTIFY) {
            endTime = System.currentTimeMillis();
            System.out.println("connect took "
                    + Long.toString(endTime - startTime));

            connected = true;
            if (DEBUG) {
                System.out.println("creating pipe" + pipeID);
            }
            //creating a peer
            int createId = peer.create(PeerNetwork.PIPE, Id, pipeID, pipeType);
          //  System.out.println("creating pipe" + pipeID);
            while (createId != responseId) {
                poll();
                if (DEBUG) {
                    System.out.println("createId: " + createId);
                }
                try {
                    Thread.sleep(config.getPollInterval() * 1000);
                } catch (Throwable t) {
                }
            }
            if (DEBUG) {
                System.out.println("Listening on " + pipeID);
            }
            peer.listen(pipeID);
        }
        return true;
    }

    private void initiateConnect() {
        if (peer == null) {
            System.out.println("initiate connect-----> creating peer instance");
            peer = PeerNetwork.createInstance(getTextField2().getString());
        }

        if (connected || connectInitiated) {
            System.out.println("initiate connect-----> return");
            return;
        }
        connectInitiated = true;
        // we will perform the actual operation in the poll thread
    }

    // for sending message to any client
    public boolean SendMessage() {//, String Peername) {
        if (peer == null || !connected) {
            initiateConnect();
            sendPending = true;
            return false;
        }
        try {
            // String pipeId = (String) peerobj.getPeerList().get(Peername);
            String pipeId = config.VIDEOP2P_PIPEID;
            System.out.println("sending message.....");
            peer.send(pipeID, sendMsg);
        } catch (Exception e) {
            System.out.println("CANNOT SEND MESSAGE!!!");
            return false;
        }
        sendMsg = null;
        return true;
    }

    public void playVideo(byte[] input) {

        System.out.println("playvideo ----> byte");
        //VideoStreaming vidstrm = new VideoStreaming();
        ByteArrayInputStream in = new ByteArrayInputStream(input);
        try {

            strmplayer = Manager.createPlayer(in, "video/3gpp");
            strmplayer.realize();
            //Get the video controller
            VideoControl video = (VideoControl) strmplayer.getControl("VideoControl");
            
            //Get a GUI to display the video
            setStreamitem((Item) video.initDisplayMode(
                    VideoControl.USE_GUI_PRIMITIVE, null));
            //setVideoitem((Item) video.initDisplayMode(
            //    VideoControl.USE_GUI_PRIMITIVE, null));
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
